<template>
  <div class="data-analysis-container">
    <div class="top">
      <div class="month br-5 active">月</div>
      <div class="year br-5">年</div>
      <el-select style="width: 116px">
        <el-option>2025</el-option>
      </el-select>
    </div>
    <div class="data-analysis-card">
      <small-card
        class="small-card"
        :title="item.title"
        :bg-color="item.bgColor"
        :end-val="item.endVal"
        :is-up="item.isUp"
        :prefix="item.prefix"
        :percent-num="item.percentNum"
        :icon-class="item.iconClass"
        v-for="(item, index) in dataAnalysisCardListData"
        :key="index"
      ></small-card>
    </div>
    <div class="chart-wrap br-20">
      <h4>收入趋势分析</h4>
      <div id="chart"></div>
    </div>
    <div class="table-wrap br-20">
      <div class="top">
        <h4>收入明细</h4>
        <div class="right">
          <el-input suffix-icon="el-icon-search" placeholder="搜寻人员"></el-input>
          <el-button type="primary" style="margin-left: 15px">
            <svg-icon icon-class="export-white"></svg-icon>
            導出
          </el-button>
        </div>
      </div>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column label="項目名稱">
          <template>
            <div>
              <div class="text-1">QUOTE-2024-001</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="客戶名稱">
          <template>
            <div class="text-1">XXXX科技公司</div>
          </template>
        </el-table-column>
        <el-table-column label="合同金額">
          <template>張三</template>
        </el-table-column>
        <el-table-column label="已付金額">
          <template>
            <span class="invoice-type">增值稅專用發票</span>
          </template>
        </el-table-column>
        <el-table-column label="未付金額">
          <template>
            <span>2025-08-06</span>
          </template>
        </el-table-column>
        <el-table-column label="付款狀態">
          <template>
            <span class="status success">已成交</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button type="text" size="small" @click.native="invoiceDetailVisible = true">詳細</el-button>
            <el-button type="text" size="small">操作</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="table-foot">
        <span></span>
        <div>
          <el-pagination background layout="sizes, prev, pager, next, jumper" :total="1000"></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import SmallCard from '@/components/SmallCard/index.vue'
import * as echarts from 'echarts'

export default {
  name: 'data-analysis-management',
  components: { SmallCard },
  mounted() {
    this.iniChart()
  },
  data() {
    return {
      chart: null,
      dataAnalysisCardListData: [
        { title: '本月總收入', prefix: '￥', endVal: 125800, isUp: false, percentNum: 12, iconClass: 'data-analysis-card-1' },
        { title: '已付收入', prefix: '￥', endVal: 58200, isUp: false, percentNum: 12, iconClass: 'data-analysis-card-2' },
        { title: '未付收入', prefix: '￥', endVal: 67600, isUp: false, percentNum: 12, iconClass: 'data-analysis-card-3' },
        { title: '付款率', prefix: '￥', endVal: 8300, isUp: true, percentNum: 12, iconClass: 'data-analysis-card-4' }
      ]
    }
  },
  methods: {
    iniChart() {
      this.chart = echarts.init(document.getElementById('chart'))
      window.addEventListener('resize', () => {
        this.chart.resize()
      })
      this.chart.setOption({
        animationDuration: 3000,
        grid: {
          left: '5%',
          right: '5%'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            crossStyle: {
              color: '#999'
            }
          }
        },
        legend: {
          data: ['已付收入', '未付收入', '增長率']
        },
        xAxis: [
          {
            type: 'category',
            data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
          }
        ],
        yAxis: [
          {
            type: 'value',
            name: '金額',
            axisLine: {
              show: true
            }
          },
          {
            type: 'value',
            name: '增長率%',
            splitLine: {
              show: false
            }
          }
        ],
        series: [
          {
            name: '已付收入',
            type: 'bar',
            barWidth: 20,
            itemStyle: {
              color: '#3C58FC'
            },
            data: [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
          },
          {
            name: '未付收入',
            type: 'bar',
            barWidth: 20,
            itemStyle: {
              color: '#36C062'
            },
            data: [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
          },
          {
            name: '增長率',
            type: 'line',
            itemStyle: {
              color: '#F9B280'
            },
            yAxisIndex: 1,
            data: [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]
          }
        ]
      })
    }
  }
}
</script>

<style scoped lang="less">
.data-analysis-container {
  .top {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 20px;
    .month,
    .year {
      cursor: pointer;
      margin-right: 10px;
      font-size: 14px;
      line-height: 20px;
      padding: 5px 20px;
      border: 1px solid rgba(0, 0, 0, 0.2);
      background: #fff;
      color: rgba(0, 0, 0, 0.5);
      &.active {
        background: #3c58fc;
        color: #fff;
      }
    }
  }
  .data-analysis-card {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    margin-bottom: 20px;
    .small-card {
      margin-right: 15px;
      //min-width: 300px;
      flex: auto;
      &:last-child {
        margin-right: 0;
      }
    }
  }
  .chart-wrap {
    height: 432px;
    background: #fff;
    padding: 30px;
    margin-bottom: 20px;
    h4 {
      margin: 0;
      font-size: 18px;
      line-height: 25px;
    }
    #chart {
      width: 100%;
      height: 100%;
    }
  }
  .table-wrap {
    background: #fff;
    padding: 25px 30px;
    .top {
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      h4 {
        font-size: 18px;
        line-height: 25px;
        margin: 0 0 25px 0;
      }
      .right {
        display: flex;
        justify-content: flex-end;
        height: 34px;
        align-items: center;
      }
    }
    .table-foot {
      margin-top: 14px;
      display: flex;
      justify-content: flex-end;
    }
  }
}
</style>
